package junior.sample.support.db.option;

import junior.db.dao.update.BatchUpdateOption;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author wubo
 * @date 2024/9/2 18:02
 */
public class BU extends BatchUpdateOption {
    
    public BU() {}
    
    public BU(boolean skipNull) {
        super(skipNull);
    }
    
    @Override
    protected void initFields() {
        super.initFields();
        
        String[] updateFields = super.getUpdateFields();
        if (updateFields == null) {
            super.withUpdateFields("updateTime", "updatedBy");
            return;
        }
        List<String> updateFieldList = new ArrayList<>(Arrays.asList(updateFields));
        if (!updateFieldList.contains("updateTime")) {
            updateFieldList.add("updateTime");
        }
        if (!updateFieldList.contains("updatedBy")) {
            updateFieldList.add("updatedBy");
        }
        super.withUpdateFields(updateFieldList.toArray(new String[0]));
    }
}
